package com.qezhhnjy.mall.coupon.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.coupon.CouponHistory;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.coupon.service.CouponHistoryService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 优惠券领取历史记录 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "优惠券领取历史记录接口")
@Slf4j
@RequestMapping("/coupon-history")
public class CouponHistoryController {
    @Resource
    private CouponHistoryService couponHistoryService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取优惠券领取历史记录信息")
    public BaseResult<CouponHistory> get(Long id) {
        CouponHistory couponHistory = couponHistoryService.getById(id);
        return BaseResult.success(couponHistory);
    }

    @PostMapping("/save")
    @Operation(summary = "新增优惠券领取历史记录信息")
    public BaseResult<CouponHistory> save(@RequestBody CouponHistory couponHistory) {
        couponHistoryService.save(couponHistory);
        return BaseResult.success(couponHistory);
    }

    @PutMapping("/update")
    @Operation(summary = "更新优惠券领取历史记录信息")
    public BaseResult<CouponHistory> update(@RequestBody CouponHistory couponHistory) {
        couponHistoryService.updateById(couponHistory);
        return BaseResult.success(couponHistory);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取优惠券领取历史记录信息")
    public BaseResult<Page<CouponHistory>> page(@RequestBody Page<CouponHistory> page) {
        couponHistoryService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除优惠券领取历史记录信息")
    public BaseResult<Long> delete(Long id) {
        couponHistoryService.removeById(id);
        return BaseResult.success(id);
    }
}

